package com.tim.arc.groovy.base
/**元编程，动态修改类、对象、方法的行为
 * .groovy；编译后继承 Script；创建时关联 Binding
 * class；编译后继承 GroovyObject；创建时关联 metaClass
 *
 * */
class Person{
    String name;
    int age;
    def sex;

    String status(){
        "happy";
    }
}

def person=new Person();
def person2=new Person();
person.name="nana";
println(person.status());
/*闭包，同java lambda表达式。格式：x,y->x+y ；无入参时可省略 ->，只写返回值 */
Person.metaClass.status={
    "smile";
}

println(person.status());
println(person2.status());
def person3=new Person();
println(person3.status());

person.metaClass.sayHello={
    println "call sayHello";
    return "Hello, ${delegate.name}";
}
println person.sayHello();

